import QtQuick 2.0
import QtQuick.Controls 2.5
import QtQuick.Layouts 1.3
import SvgImage 1.0

Rectangle {
    id: root
    radius: 4
    color: _normal_color

    property alias _text: t.text
    property int _fontSize: Theme.font_size_13
    property bool needs_icon: false
    property int icon_width: 16
    property int icon_height: 16
    property string icon_source: ""

    signal clicked()

    property color _normal_color: "#3986FF"
    property color _hover_color: "#5F9DFF"
    property color _pressed_color: "#096DD9"
    property color _disable_color: "#BDD6FC"

    onEnabledChanged: {
        if( !enabled ){
            root.color = _disable_color
        }else{
            root.color = _normal_color
        }
    }

    MouseArea {
        anchors.fill: parent
        hoverEnabled: true
        onClicked: { root.clicked(); root.focus = true }
        onEntered: { color = _hover_color }
        onExited: { color = _normal_color }
        onPressed: { color = _pressed_color }
        onReleased: { color = _normal_color }
    }

    RowLayout {
        anchors.fill: parent
        spacing: 0

        Item { Layout.fillWidth: true }

        Rectangle {
            implicitWidth: icon_width
            implicitHeight: icon_height
            Layout.rightMargin: 8
            color: "transparent"
            visible: needs_icon

            SvgImage {
                anchors.fill: parent
                source: icon_source
            }
        }

        CusText {
            id: t
            text: root.text
            font.pixelSize: _fontSize
            color: "white"
        }

        Item { Layout.fillWidth: true }

    }
}
